/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package foxmob.mlts.viewcontroller;

import foxmob.mlts.controller.setter.NewTestRecordFormController;
import foxmob.mlts.viewcontroller.marker.MarkAnswerForm;
import foxmob.mlts.viewcontroller.setter.NewTestRecordForm;
import foxmob.mlts.viewcontroller.setter.OpenTestRecordForm;
import foxmob.mlts.viewcontroller.setter.SetterForm;
import foxmob.mlts.viewcontroller.student.QuestionPaperForm;
import javax.swing.JFrame;

/**
 *
 * @author May
 */
public class MainPage extends javax.swing.JFrame {

    /**
     * Creates new form MainPage
     */
    public MainPage() {
        initComponents();
        initForm();
    }
    
    private void initForm() {
        paperForm = new QuestionPaperForm();
        setterForm = new SetterForm();
        markAnswerForm = new MarkAnswerForm();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jButtonStudent = new javax.swing.JButton();
        jButtonSetter = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jButtonMarker = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 31)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(153, 180, 209));
        jLabel1.setText("MELT System");

        jButtonStudent.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonStudent.setText("Student");
        jButtonStudent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStudentActionPerformed(evt);
            }
        });

        jButtonSetter.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonSetter.setText("Setter");
        jButtonSetter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSetterActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Please select your role:");

        jButtonMarker.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButtonMarker.setText("Marker");
        jButtonMarker.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMarkerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(143, 143, 143)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(102, 102, 102)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonStudent, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                            .addComponent(jButtonSetter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonMarker, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE))))
                .addContainerGap(135, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(111, 111, 111)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                .addGap(129, 129, 129))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jLabel2)
                .addGap(30, 30, 30)
                .addComponent(jButtonStudent)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonSetter)
                .addGap(12, 12, 12)
                .addComponent(jButtonMarker)
                .addContainerGap(72, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonStudentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStudentActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        paperForm.setVisible(true);
        paperForm.loadTestRecord();
    }//GEN-LAST:event_jButtonStudentActionPerformed

    private void jButtonSetterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSetterActionPerformed

        // TODO add your handling code here:
        OpenTestRecordForm openRecordForm = 
                new OpenTestRecordForm(setterForm.getSetterFormController());
        this.setVisible(false);
        // validate open or new test record
        if (openRecordForm.getOpenTestRecordFormController().loadTestRecord()) {
            openRecordForm.setVisible(true);
        } else {
            NewTestRecordForm newRecordForm =
                    new NewTestRecordForm(setterForm.getSetterFormController());
            newRecordForm.setVisible(true);
        }
    }//GEN-LAST:event_jButtonSetterActionPerformed

    private void jButtonMarkerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMarkerActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
        markAnswerForm.getMarkAnswerFormController().loadFillInListData();
        markAnswerForm.setVisible(true);
    }//GEN-LAST:event_jButtonMarkerActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainPage.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainPage().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonMarker;
    private javax.swing.JButton jButtonSetter;
    private javax.swing.JButton jButtonStudent;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables

    private SetterForm setterForm;
    private QuestionPaperForm paperForm;
    private MarkAnswerForm markAnswerForm;
}
